perm filename A18.TEX[106,RWF] blob sn#807716 filedate 1985-09-20 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	\magnification\magstephalf
C00012 ENDMK
C⊗;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
  January\or February\or March\or April\or May\or June\or
  July\or August\or September\or October\or November\or December\fi
  \space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a18.tex[106,phy] \today\hfill}

\bigskip
\line{\bf [Subject: Introduction.]\hfill}

\bigskip
An introductory text in programming, to avoid leaving the reader hopelessly
confused, must largely work within one programming language as implemented
on one computer. This book uses Pascal as that language, and where the
details of the implementing computer are important, refers to the characteristics
of the DEC System~20 as used at the Stanford University LOTS installation.
The reader should remember that the fundamental ideas of computer programming
may be used in a variety of contexts:

\smallskip
\disleft 25pt:(1):
Hand calculation on the back of an envelope. Speed about one digit per second.
Storage capacity about 100~digits. Precision as desired. Number base ten.

\smallskip
\disleft 25pt:(2):
Hand-held four-function pocket calculator. Speed about ten digits per second.
Storage capacity about 20~digits, supplemented by paper. Precision six to
ten places. Number base ten.

\smallskip
\disleft 25pt:(3):
Home computer, based on a standard microprocessor such as the ???? or ????.
Speed about ??? digits per second. Storage capacity about 30,000 digits.
Precision about six places. Number base two.

\smallskip
\disleft 25pt:(4):
Full sized business computer, as in banking. Speed about $10↑7$~digits
per second. Storage capacity about $10↑9$~digits. Precision as desired,
up to perhaps ???? places. Number base usually ten.

\smallskip
\disleft 25pt:(5):
Full sized scientific computer. Speed and capacity as in~(4). Precision
between six and fourteen places. Number base two, eight, or sixteen.

\smallskip
\disleft 25pt:(6):
``Supercomputer'', perhaps for global weather simulation. Speed about
$10↑9$~digits per second. Storage capacity about $10↑{10}$~digits. Precision
about ???? places. Number base two.

\smallskip
Problems and examples are used, therefore, which may not be relevant
to the reader's immediate computing environment. For example, how could
you evaluate
$$\eqalignno{X&=A+BY+CY↑2\cr
\noalign{\hbox{and}\hfill}
Z&=A/(B+C)\cr}$$
on a simple (memoryless) pocket calculator without writing down any
intermediate results? For~$X$, restate the formula as
$X=(C\cdot Y+B)\cdot Y+A$. On some calculators, the key sequence
$$B+C=/A=$$
giving the value of $1/Z$, can be followed by $/=$ or $/==$ to get~$Z$,
the reciprocal.

It is not obligatory to do things the hard way by computer, especially
when you would find an easy way if you were doing it by hand. Given the
latitude and longitude of Chicago, Boston, and Dallas, I~want to find which
of Boston and Dallas is closer 
to Chicago by air. I~could use a horrendous formula
to find the great circle distance, but it is much simpler to convert the
polar coordinates to rectangular, compute the straight line distance
right through the earth, and use the fact that the lesser straight line
distance goes with the lesser great circle distance.

\bigskip
\noindent{\bf Case Study: Bathtub Mathematics.}

By air, is Chicago closer to Boston or to Dallas? Measurement on a map is
risky, because all map projections distort distances. I~will calculate
the distances from the latitude and longitude:
$$\vcenter{\halign{\lft{#}\qquad&\ctr{#}\quad&\ctr{#}\cr
&latitude$(N)$&longitude$(W)$\cr
\noalign{\smallskip}
Boston&$42↑{\circ}21'24''$&$71↑{\circ}03'25''$\cr
Chicago&$41↑{\circ}52'28''$&$87↑{\circ}38'22''$\cr
Dallas&$32↑{\circ}47'09''$&$96↑{\circ}47'37''$\cr}}$$

I could determine the great circle distance by working out or looking up 
a~humongous formula, but that would probably entail getting out of the bathtub
along the way. A~key insight is that short airline distances correspond to
short ``tunnel'' distances: I~can compute rectangular coordinates for each
city, find the Euclidean distances by the Pythagorean theorem, and see
which distance is greater.
In fact, the square of the distance will do just as well; the larger airline
distance will go with the larger straight line distance, which will go with
the larger value of $\hbox{distance}↑2=(X↓1-Y↓1)↑2+(Y↓1-Y↓2)↑2+(Z↓1-Z↓2)↑2$.

I start with Boston. My unit of distance will be earth radii, so that
I~don't need to look up that radius in feet, miles, or meters. Boston
is above the equator by $Z=\sin\hbox{lat}$, and distant from the polar
axis by $\sqrt{X↑2+Y↑2}=\cos\hbox{lat}$. My pocket calculator can give me
both in one operation, by a built-in polar-to-rectangular conversion.
I~key in the radius of~1, the ``$P→R$'' key, and the latitude. The angles,
thanks to Casio's designers, may be entered directly in degrees, minutes, and
seconds. So, after keying 1~``$P→R$'' $42↑{\circ}21'24'' =$,
I~see the value of $\sqrt{X↑2+Y↑2}=0.7390$. Pressing the
``$X\leftrightarrow Y$'' key displays $Z=0.6737$, which I~write down.
Pressing the ``$X\leftrightarrow Y$'' key again displays
$\sqrt{X↑2+Y↑2}$. Now, working with this radius in the ($X$--$Y$) plane of
the equator, I~do another polar-to-rectangular conversion, using the
longitude as the angle. After keying ``$P→R$'' $71↑{\circ}03'25''=$,
I~write down from the display $Y=0.2399$, and pressing ``$X\leftrightarrow Y$''
again, $X=0.6989$. I~do the same for the other cities.
$$\vcenter{\halign{\lft{#}\qquad&$\ctr{#}$\quad&$\ctr{#}$\quad&$\ctr{#}$\cr
&X&Y&Z\cr
\noalign{\smallskip}
Boston&0.6989&\phantom{-}0.2399&0.6737\cr
Chicago&0.7439&\phantom{-}0.0307&0.6675\cr
Dallas&0.8348&-0.0994&0.5415\cr}}$$
The $\hbox{distance}↑2$ from Chicago to Boston is $(0.7439-0.6989)↑2+
(0.0307-0.2399)↑2+(0.6675-0.6737)↑2=0.04583$; the distance itself is
0.2141 ($=848$ miles). Similarly, the $\hbox{distance}↑2$ from Chicago
to Dallas is 0.04106; the distance itself is 0.2026 ($=803$ miles).
Dallas is closer. The published distances by road to Boston and Dallas
are, respectively, 975 and 936~miles. The great circle distances are
850 and 804~miles.


\bigskip
\parindent0pt
\copyright 1984 Robert W. Floyd

First draft July 20, 1984

\bye